package com.crpc;

import com.crpc.core.CrpcBootStrap;
import com.crpc.core.ReferenceConfig;
import com.crpc.core.discovery.RegistryConfig;
import com.rpc.HelloCrpc;
import lombok.extern.slf4j.Slf4j;

/**
 * Hello world!
 */
@Slf4j
public class ConsumerApplication {
    public static void main(String[] args) throws InterruptedException {
        ReferenceConfig<HelloCrpc> reference = new ReferenceConfig<>();
        reference.setInterfaceProvider(HelloCrpc.class);

        ReferenceConfig<HelloCrpc> reference2 = new ReferenceConfig<>();
        reference.setInterfaceProvider(HelloCrpc.class);

        //代理
        //链接注册中心
        //拉取服务列表
        //选择一个服务并建立连接
        //4.发送一个请求，携带一些信息
        CrpcBootStrap.getInstance()
                .application("consumer")
                .registry(new RegistryConfig("zookeeper://127.0.0.1:21810"))
                .serialize("json")
                .compress("gzip")
                .reference(reference);


        HelloCrpc helloCrpc = reference.get();
        for (int i = 0; i < 10; i++) {
            String result = helloCrpc.sayHi("南京工业大学浦江学院");
            log.info("消费者发起请求,服务端给予的响应=====>{}", result);
            Thread.sleep(500);
        }
//        String first = helloCrpc.sayHi("南京工业大学浦江学院");
//        log.info("消费者发起请求,服务端给予的响应=====>{}", first);

    }
}
